home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / util / compress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  937 b   |  53 lines

  1. /* compress: compress out redundant, & strip trailing linear white space */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/util/RCS/compress.c,v 6.0 1991/12/18 20:25:18 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/util/RCS/compress.c,v 6.0 1991/12/18 20:25:18 jpo Rel $
  9.  *
  10.  * $Log: compress.c,v $
  11.  * Revision 6.0  1991/12/18  20:25:18  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19.  
  20.  
  21. char *compress (fromptr, toptr)
  22. register char   *fromptr;
  23. register char   *toptr;
  24. {
  25.     register char   chr;
  26.     char        *in_toptr = toptr;
  27.     /*
  28.     init to skip leading spaces
  29.     */
  30.     chr = ' ';
  31.  
  32.     while ((*toptr = *fromptr++) != '\0') {
  33.         /*
  34.         convert newlines and tabs to only save first space
  35.         */
  36.         if (isspace (*toptr)) {
  37.             if (chr != ' ')
  38.                 *toptr++ = chr = ' ';
  39.         }
  40.         else
  41.             chr = *toptr++;
  42.     }
  43.  
  44.  
  45.     /*
  46.     remove trailing space if any
  47.     */
  48.     if ((chr == ' ')
  49.         && (toptr != in_toptr))
  50.         *--toptr = '\0';
  51.     return (toptr);
  52. }
  53.